import Mock from "mockjs";

// 设置延迟时间
Mock.setup({
  timeout: "200-600",
});

// 模拟用户数据
Mock.mock(/\/api\/user\/info/, "get", {
  code: 200,
  message: "获取成功",
  data: {
    "id|1-100": 1,
    name: "@cname",
    avatar: '@image("200x200","#50B347", "#FFF", "Avatar")',
    email: "@email",
    address: "@county(true)",
    "age|18-60": 25,
  },
});

// 模拟用户列表数据
Mock.mock(/\/api\/user\/list.*/, "get", (options) => {
  const url = new URL(options.url, "http://localhost");
  const page = parseInt(url.searchParams.get("page") || "1");
  const pageSize = parseInt(url.searchParams.get("pageSize") || "10");

  const list = Mock.mock({
    [`list|${pageSize}`]: [{
      "id|+1": (page - 1) * pageSize + 1,
      name: "@cname",
      avatar: '@image("200x200","#50B347", "#FFF", "Avatar")',
      email: "@email",
      address: "@county(true)",
      "age|18-60": 25,
    }],
  }).list;

  return {
    code: 200,
    message: "获取成功",
    data: {
      total: 100,
      list,
    },
  };
});

export default Mock;